

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import webpage.AddRemoveFriend;

/**
 * Servlet implementation class FriendsAction
 */
@WebServlet("/FriendsAction")
public class FriendsAction extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FriendsAction() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String loginEmail =(String)request.getSession().getAttribute("loginEmail");
		String emailaddress =(String)request.getSession().getAttribute("emailaddress");
		String friends =(String)request.getSession().getAttribute("friends");
		System.out.println(loginEmail+emailaddress+friends);
		AddRemoveFriend action = new AddRemoveFriend();
		String result=null;
		
		if (friends.equals("Add as a friend")){
			result =action.addFriend(loginEmail, emailaddress);
			}
		else if (friends.equals("Remove from friends")) {
			result= action.removeFriend(loginEmail, emailaddress);
		}
		System.out.println(result);
		request.setAttribute("friendresult", result);
		RequestDispatcher rd;
		rd= request.getRequestDispatcher("Profile.jsp");
		rd.forward(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
